package com.buaa.student.controller;

import com.buaa.student.pojo.Student;
import com.buaa.student.service.StudentQueryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;

@Slf4j
@Controller
public class StudentQueryController {

    @Autowired
    private StudentQueryService studentQueryService;

    @GetMapping("/student/query")
    public String QueryStudentByKey(@RequestParam("key") String key, Model model){

        String newKey = '%'+key+'%';
        System.out.println("key值是："+newKey);

        ArrayList<Student> students = studentQueryService.QueryByKey(newKey);
        model.addAttribute("students",students);

        return "index";
    }

    @GetMapping(value = {"/index", "/"})
    public String index(){

        return "index";
    }


}
